/*
 * @Date: 2023-12-11 16:32:30
 * @LastEditors: lyx
 * @LastEditTime: 2024-01-31 10:37:25
 * @FilePath: \mt-middleware-server\src\app.module.ts
 * @Description:
 */
import { Global, Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PostsModule } from './posts/posts.module';
import { DbModule } from '@libs/db';
import { WeappModule } from './weapp/weapp.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import config from 'config/config';
import { HttpModule } from '@nestjs/axios';
import { FeishuModule } from './feishu/feishu.module';
import { TaskKafkaModule } from './task-kafka/task-kafka.module';
import { WsStartGateway } from './gateway/ws.gateway';
import { FeishuService } from './feishu/feishu.service';
import { LogsWinstonModule } from './common/logs-winston/logs-winston.module';
import { ObpModule } from './obp/obp.module';
import { ObpService } from './obp/obp.service';
import * as  tunnel from 'tunnel';

@Global()
@Module({
  imports: [
    LogsWinstonModule,
    ConfigModule.forRoot({
      isGlobal: true,
      load: [config],
    }),
    // ! 使用环境变量
    HttpModule.register({
      timeout: 60000,
      maxRedirects: 5,
      httpsAgent:tunnel.httpsOverHttp({
        proxy:process.env.proxy_host? {
            host: process.env.proxy_host,
            port: process.env.proxy_port,
        }:null
      })
    }),
    // ! 使用nacos: 暂时无法获取到注册后的内容
    // HttpModule.registerAsync({
    //   imports: [ConfigModule],
    //   inject: [ConfigService],
    //   useFactory: async (configSerivce: ConfigService) => {
    //     console.log('configSerivce.get(`proxy.proxy_host`)',configSerivce.get(`proxy.proxy_host`));
    //     return {
    //         timeout: 60000,
    //         maxRedirects: 5,
    //         httpsAgent:tunnel.httpsOverHttp({
    //           proxy:configSerivce.get(`proxy.proxy_host`)? {
    //               host: configSerivce.get(`proxy.proxy_host`),
    //               port: configSerivce.get(`proxy.proxy_port`),
    //           }:null
    //         })
    //     }
    //   },
    // }),
    DbModule,
    PostsModule,
    WeappModule,
    FeishuModule,
    TaskKafkaModule,
    ObpModule,
  ],
  controllers: [AppController],
  providers: [AppService, FeishuService, ObpService, WsStartGateway],
  exports: [HttpModule],
})
export class AppModule {}
